package com.example.sneakerappforme1105.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.example.sneakerappforme1105.bean.Order;
import com.example.sneakerappforme1105.bean.OrderItem;
import com.example.sneakerappforme1105.bean.User;

import java.util.List;

@Dao
public interface OrderDao {

    @Query("SELECT * FROM tb_order WHERE userId =:userId")
    List<Order> queryAllOrderByUserId(long userId); //  查询某个用户的所有订单项

    @Query("SELECT * FROM tb_order WHERE userId =:userId AND status=:status")
    List<Order> queryOrderByStatus(long userId, String status);

    @Query("SELECT * FROM tb_order WHERE orderId=:orderId")
    Order queryOrderById(long orderId);  // 查询某个订单 商家用吧

//    @Query("SELECT * FROM tb_orderItem INNER JOIN tb_order ON tb_orderItem.orderId = tb_order.orderId WHERE tb_order.orderId =:orderId")
//    List<OrderItem> queryOrderItemsByOrderId(long orderId); // 根据当前订单查询所有商品项目

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertOneOrder(Order order);

    @Update(onConflict = OnConflictStrategy.REPLACE)
    int updateOrder(Order order); // 更新商品信息

    @Query("DELETE FROM tb_order WHERE orderId = :orderId")
    void deleteOrderByOrderId(long orderId); // 根据订单Id 删除， 需要先删除 orderId 关联的订单项





}
